#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "image.h"
#include "splite.h"

#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    menuInit();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::menuInit()
{
    QAction* importImage = ui->menuBar->addAction(QString("导入图片"));
    QAction* spliteImage = ui->menuBar->addAction(QString("切割图片"));
    QAction* saveImage = ui->menuBar->addAction(QString("保存图片"));
    QAction* calcImage = ui->menuBar->addAction(QString("算法"));
    connect(importImage,&QAction::triggered,this,&MainWindow::sltImportImage);
    connect(spliteImage,&QAction::triggered,this,&MainWindow::sltSpliteImage);
    connect(saveImage,&QAction::triggered,this,&MainWindow::sltSaveImage);
    connect(calcImage,&QAction::triggered,this,&MainWindow::sltcalcImage);
}

void MainWindow::sltImportImage()
{
    QString imagePath = QFileDialog::getOpenFileName(this,"导入图片","./","*png *jpg");
    int imageWidth = 0,imageHeight = 0;
    ui->iamge->imageLoad(imagePath,imageWidth,imageHeight);
    ui->iamge->imageData();
    this->resize(imageWidth,imageHeight);
}

void MainWindow::sltSpliteImage()
{
    splite *_splite = new splite();
    _splite->show();
    connect(_splite,&splite::sign_spliteinfo,[=](int x,int y)
    {
        QList<QImage> imageItems;
        ui->iamge->iamgeItems(x,y,imageItems);
        ui->iamge->imageShow();
    });
}

void MainWindow::sltSaveImage()
{
    ui->iamge->imageSave();
}

void MainWindow::sltcalcImage()
{

}
